<%@ tag body-content="empty" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="spring-sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="cf" uri="http://kyub.com/jsp/jstl/functions" %>
<%@ attribute name="pojoDescriptor" required="true" type="com.kyub.spring.gears.model.PojoDescriptor" %>
<%@ attribute name="pojo" required="true" type="java.lang.Object" %>
<%@ attribute name="gears_restfull_prefix" required="true" %>


<h2>${pojoDescriptor.name}</h2>

<table>

    <tr>
        <c:forEach items="${pojoDescriptor.listFields}" var="p">
            <th>
                <c:choose>
                    <c:when test="${!cf:isStructProperty(p) or (cf:isStructProperty(p) and p.layout.label == null)}">
                        <spring:message var="colTitle" code="${pojoDescriptor.name}.${p.name}.labelList"
                                        text="${p.name}"
                                        htmlEscape="true"/>
                    </c:when>
                    <c:otherwise>
                        <c:set var="colTitle" value=""/>
                    </c:otherwise>
                </c:choose>
                <c:out value="${colTitle}"/>
            </th>
        </c:forEach>
        <th colspan="2"></th>
    </tr>
    <c:forEach items="${pojoList}" var="pojo">
        <c:forEach items="${pojoDescriptor.listFields}" var="p">
            <c:if test="${!cf:isStructProperty(p) or (cf:isStructProperty(p) and p.layout.label == null)}">
                <spring:message var="colTitle" code="${pojoDescriptor.name}.${p.name}.labelList" text="${p.name}"
                                htmlEscape="true"/>
            </c:if>
            <td sortable="true" title="${colTitle}">
                <c:choose>
                    <c:when test="${cf:isSimpleProperty(p)}">
                        <c:choose>
                            <c:when test="${cf:readProperty(pojo,p.name).class.simpleName == 'Date'}">
                                <fmt:formatDate value="${cf:readProperty(pojo,p.name)}"/>
                            </c:when>
                            <c:when test="${cf:readProperty(pojo,p.name).class.simpleName == 'Boolean'}">
                                <c:choose>
                                    <c:when test="${cf:readProperty(pojo,p.name)}">
                                        <span class="ui-icon ui-icon-check"></span>
                                    </c:when>
                                    <c:otherwise>
                                        <span class="ui-icon ui-icon-closethick"></span>
                                    </c:otherwise>
                                </c:choose>
                            </c:when>
                            <c:otherwise>
                                ${cf:readProperty(pojo,p.name)}
                            </c:otherwise>
                        </c:choose>

                    </c:when>
                    <c:when test="${cf:isRelation(p)}">

                        ${cf:readProperty(pojo,p.name)}

                    </c:when>

                    <c:when test="${cf:isStructProperty(p)}">
                        <!--
                        ${p.layout.hrefPattern != null}  ${p.layout.label != null}
                        -->
                        <c:choose>
                            <c:when test="${p.layout.hrefPattern != null}">

                                <a href="${cf:buildHref(p.layout, pojo,pageContext.request.contextPath)}">
                                    <c:choose>
                                        <c:when test="${p.layout.label != null}">
                                            <spring:message code="${pojoDescriptor.name}.${p.layout.label}"
                                                            text="${p.layout.label}" htmlEscape="false"/>
                                        </c:when>
                                        <c:otherwise>
                                            ${cf:readProperty(pojo,p.property.name)}
                                        </c:otherwise>
                                    </c:choose>
                                </a>
                            </c:when>

                            <c:otherwise>
                                <c:when test="${p.layout.label != null}">
                                    <spring:message code="${pojoDescriptor.name}.${p.layout.label}"
                                                    text="${p.layout.label}"
                                                    htmlEscape="false"/>
                                </c:when>
                                <c:otherwise>
                                    ${cf:readProperty(pojo,p.property.name)}
                                </c:otherwise>
                            </c:otherwise>

                        </c:choose>


                    </c:when>
                    <c:otherwise>
                        ${p} ${p.class}
                    </c:otherwise>
                </c:choose>

            </td>
        </c:forEach>


        </tr>
    </c:forEach>
</table>


